package com.aner.test.security.service;

import com.aner.test.cache.DataCache;
import com.aner.test.security.LoginUser;
import org.slf4j.Logger;
import com.aner.tester.utils.LoggerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * user validation
 *
 * @author aner
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService
{
    private static final Logger log = LoggerUtils.getLogger(UserDetailsServiceImpl.class);

    @Autowired
    DataCache dataCache;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException
    {

        String password = dataCache.getUserInfo(username);
        return new LoginUser(username, password);
    }

}
